package com.hanoi.wiki.model.json;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.codehaus.jackson.map.annotate.JsonSerialize;

import com.hanoi.wiki.common.DateSerializer;
import com.hanoi.wiki.model.Category;
import com.hanoi.wiki.model.Log;
import com.hanoi.wiki.model.Places;
import com.hanoi.wiki.model.Rates;

public class PlacesJson extends BaseJsonObject implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private int id;	
	private String address;
	private int status;	
	private Date updateTime;
	private String note;
	private int rate;
	private List<Integer> logs;
	private List<Integer> categories;
	
	public PlacesJson() {
		logs = new ArrayList<Integer>();
		categories = new ArrayList<Integer>();
	}
	
	public PlacesJson(Places places) {
		if(places != null) {
			this.id = places.getId();
			this.address = places.getAddress();
			this.status = places.getStatus();
			this.updateTime = places.getUpdatedTime();
			this.note = places.getNote();
				
			Rates rates = places.getRate();
			if(rates != null) {
				this.rate = rates.getId();
			}
			
			for(Log log : places.getLogs()) {
				if(log != null) {
					this.logs.add(log.getId());
				}
			}
			
			for(Category category : places.getCategories()) {
				if(category != null) {
					this.categories.add(category.getId());
				}
			}
		}
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	@JsonSerialize(using=DateSerializer.class)
	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	public String getNote() {
		return note;
	}

	public void setNote(String note) {
		this.note = note;
	}

	public int getRate() {
		return rate;
	}

	public void setRate(int rate) {
		this.rate = rate;
	}

	public List<Integer> getLogs() {
		return logs;
	}

	public void setLogs(List<Integer> logs) {
		this.logs = logs;
	}

	public List<Integer> getCategories() {
		return categories;
	}

	public void setCategories(List<Integer> categories) {
		this.categories = categories;
	}
}
